package com.ssyt.store.sys.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ssyt.store.common.BaseDao;
import com.ssyt.store.sys.dao.StoreOrderDao;
import com.ssyt.store.sys.entity.StoreOrder;

@Repository
public class StoreOrderDaoImpl extends BaseDao<StoreOrder, String> implements StoreOrderDao {

	@Override
	public List<StoreOrder> getStoreOrder(String userId) {
		return listEntityByHql("FROM StoreOrder WHERE sysUserId=? AND state=1", userId);
	}

	@Override
	public String addStoreOrder(StoreOrder storeOrder) {
		return save(storeOrder);
	}

	@Override
	public void deleteStoreOrder(String id) {
		StoreOrder storeOrder = get(id);
		storeOrder.setState((byte)2);
		update(storeOrder);
	}

	@Override
	public void receiveProduct(String id) {
		StoreOrder storeOrder = get(id);
		storeOrder.setPayState((byte)3);
		update(storeOrder);
	}

	@Override
	public void sendProduct(String id) {
		StoreOrder storeOrder = get(id);
		storeOrder.setPayState((byte)2);
		update(storeOrder);
	}

	@Override
	public List<StoreOrder> listAllStoreOrder() {
		return listEntityByHql("FROM StoreOrder WHERE state=1 ORDER BY payState");
	}

}
